﻿/*
* 作者:haojielyb
* 邮箱:haojielyb@qq.com
*/

using SixLabors.ImageSharp;
using System;

using System.IO;

namespace HanwangService
{
    public class OthTool
    {
        public static void Base64StringToImage(string base64Img, string imgPath)
        {
            byte[] bytes = Convert.FromBase64String(base64Img);



            using (var image = Image.Load(bytes))
            {

                image.SaveAsJpeg(imgPath);//.Save(outputStream, format);
            }


        }
        public static string ToBase64String(string imgPath)
        {
            byte[] fileBytes=null ;

            try
            {
                fileBytes = File.ReadAllBytes(imgPath);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"Error reading file '{imgPath}': {ex.Message}");
               // throw ex;
            }

            return Convert.ToBase64String(fileBytes);


        }
    }
}